<!--
 * @Description: 
 * @version: 
 * @Author: liurui
 * @Date: 2024-02-04 15:43:05
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2024-02-04 15:56:33
-->
<template>
    <div>

    </div>
</template>

<script setup lang="ts">
// 实现 Replace<S, From, To> 将字符串 S 中的第一个子字符串 From 替换为 To
type myReplace<S extends string, From extends string, To extends string> = 
    // 确保 From 不是空字符串
    From extends '' ? S :
    // 通过推断匹配 L From R
    S extends `${infer L}${From}${infer R}` ? 
    // 递归组成新的字段
        `${L}${To}${myReplace<R, From, To>}` : S;

type replaced = myReplace<'types are fun!', 'fun', 'awesome'>; // 期望是 'types are awesome!'
</script>

<style scoped>

</style>